<!-- 发布分享 -->
<template>
  <div>
    <van-nav-bar
      title="发布分享"
      left-text="返回"
      @click-left="onClickLeft"
      left-arrow
      style="margin-bottom: 6px"
    />
    <van-form @submit="onSubmit" style="padding-right: 6px">
      <van-cell-group>
        <van-field v-model="value" label="标题" placeholder="请输入标题" />
      </van-cell-group>
      <van-field
        v-model="message"
        rows="1"
        autosize
        label="内容"
        type="textarea"
        placeholder="请输入内容"
      />
      <van-field
        readonly
        clickable
        name="picker"
        :value="selectValue"
        label="所属专题"
        placeholder="点击选择专题"
        @click="showPicker = true"
      />
      <van-popup
        v-model="showPicker"
        position="bottom"
        style="border-radius: 15px 15px 0 0"
      >
        <van-picker
          show-toolbar
          :columns="columns"
          @confirm="onConfirm"
          @cancel="showPicker = false"
        />
      </van-popup>
      <van-field name="uploader" label="分享图片">
        <template #input>
          <van-uploader v-model="uploader" />
        </template>
      </van-field>
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit" @click="send"
          >发布</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { Toast } from "vant";
import {mapState} from "vuex";

export default {
  name: "PostShare",
  data() {
    return {
      value: "",
      message: "",
      uploader: [],
      selectValue: "",
      columns: ["兼职区", "考证区", "考研区", "游戏区", "专业区","情感区","物理区","高数区"],
      showPicker: false,
    };
  },
  computed: {
    ...mapState(['userinfo'])
  },
  methods: {
    onClickLeft() {
      Toast("返回");
      history.go(-1)
    },
    onSubmit(values) {
      console.log("submit", values);
    },
    onConfirm(selectValue) {
      this.selectValue = selectValue;
      this.showPicker = false;
    },
    send(){
      let id = 1001
      switch (this.selectValue){
        case "兼职区": id = 1008
              break;
        case "考证区": id = 1007
              break;
        case "考研区": id = 1006
              break;
        case "游戏区": id = 1005
              break;
        case "专业区": id = 1004
              break;
        case "情感区": id = 1003
              break;
        case "物理区": id = 1002
              break;
        case "高数区": id = 1001
      }
      const dat ={
        modelId: id,
        title: this.value,
        content: this.message,
        userId: this.userinfo.id
      }
      const url ="http://localhost:10004/article/add-new"
      this.axios.post(url,dat).then(response => {
        if(response.data.state==200){
          console.log("发布成功",response.data.data)
          this.$router.push("/homeview/my/mypage/personalPage")
        }else{
          console.log("发布失败",response.data.data)
        }
      })
      console.log("分享发布",dat)
    }
  },
};
</script>

<style scoped>
</style>